//
//  ViewController.m
//  功能模块代码
//
//  Created by apple  on 2017/10/31.
//  Copyright © 2017年 JMZ. All rights reserved.
//

#import "ViewController.h"
#import "SelectProductViewController.h"
#import "ConnectWifiViewController.h"
#import "BGColorDemoViewController.h"
#import "XGCameraController.h"
#import "MARFaceBeautyController.h"
#import "AlertTableViewController.h"
#import "ActionSheetTableViewController.h"
#import "SlideViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *cellArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _cellArray = [NSArray arrayWithObjects:@"选择图片模块",@"城市WiFi功能",@"打开微信",@"打开支付宝",@"NavBar透明变不透明",@"自定义相机拍照",@"美颜相机",@"弹窗Alert",@"弹窗ActionSheet",@"横向滑动标签", nil];
    
    [self initMainVC];
}

- (void)initMainVC
{
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellId"];
    [self.view addSubview:_tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];
    }
    cell.textLabel.text = _cellArray[indexPath.row];
    
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _cellArray.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        SelectProductViewController *VC = [[SelectProductViewController alloc] init];
       [self.navigationController pushViewController:VC animated:YES];
        
    }else if(indexPath.row == 1) {
        ConnectWifiViewController *VC = [[ConnectWifiViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
       
    }else if (indexPath.row == 2) {
        // 将自己的url Schemes通过参数的形式传递过去，
        NSString *urlStr = @"weixin://";
        NSURL *url = [NSURL URLWithString:urlStr];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            // 3. 打开应用程序
            if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
                [[UIApplication sharedApplication] openURL:url options:@{}
                   completionHandler:^(BOOL success) {
                       
                   }];
            } else {
                BOOL success = [[UIApplication sharedApplication] openURL:url];
                
            }
        } else {
            NSLog(@"没有安装微信");
        }
        
        
    
    }else if (indexPath.row == 3) {
        // 将自己的url Schemes通过参数的形式传递过去，
        NSString *urlStr = @"alipay://";
        NSURL *url = [NSURL URLWithString:urlStr];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            // 3. 打开应用程序
            if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
                [[UIApplication sharedApplication] openURL:url options:@{}
                                         completionHandler:^(BOOL success) {
                                             
                                         }];
            } else {
                BOOL success = [[UIApplication sharedApplication] openURL:url];
                
            }
        } else {
            NSLog(@"没有安装支付宝");
        }
    }else if (indexPath.row == 4) {
        BGColorDemoViewController *VC = [[BGColorDemoViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }else if (indexPath.row == 5) {
        XGCameraController *cameraVC = [XGCameraController new];
        [self presentViewController:cameraVC animated:YES completion:nil];
    }else if (indexPath.row == 6) {
        MARFaceBeautyController *VC = [[MARFaceBeautyController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }else if (indexPath.row == 7) {
        AlertTableViewController *VC =   [[AlertTableViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }else if (indexPath.row == 8) {
        ActionSheetTableViewController *VC = [[ActionSheetTableViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }else if (indexPath.row == 9) {
        SlideViewController *VC = [[SlideViewController alloc] init];
        [self.navigationController pushViewController:VC animated:YES];
    }
}

@end
